package nrrg.zhujuxing.application.learnscala

object lambdaFucntion {
  def main(args: Array[String]): Unit = {
    val fun = (name: String) => {
      println(name)
    }
    //    fun("nrrg")

    def f(func: String => Unit): Unit = {
      func("1")
      func("2")
    }

    f(fun)

    def BinaryPrameterFunc(func: (Int, Int) => Int): Unit = {
      println(func(1, 2))
    }

    val add = (a: Int, b: Int) => a + b
    val minus = (a: Int, b: Int) => a - b
    BinaryPrameterFunc(add)
    BinaryPrameterFunc(minus)
    BinaryPrameterFunc(-_ + _)

    println("---------------------------------")
    val arr: Array[Int] = Array(1, 2, 3, 4, 5)

    def arrOp(array: Array[Int], op: Int => Int): Array[Int] = {
      for (elem <- array) yield op(elem)
    }

    val arr2:Array[Int] = arrOp(arr, _ * 2)
    arr2.foreach(println)
    println(arr2.mkString(","))

  }
}
